// 路由配置信息
/*
()=>import('@/pages/Home')路由懒加载
当打包构建应用时，JavaScript 包会变得非常大，影响页面加载。
如果我们能把不同路由对应的组件分割成不同的代码块，然后当路由被访问的时候才加载对应组件，这样就更加高效了。
*/
export default [
  // 重定向路由
  { path: '/', redirect: '/home' },
  { path: '/home', component: ()=>import('@/pages/Home'), meta: { show: true } },
  { path: '/search/:keyword?', component: ()=>import('@/pages/Search'),
  meta: { show: true },
  name: "search",
  // 路由组件能不能传递props参数---‘可以的’
  // 布尔值写法：只能传递 params
  // props: true
  // 对象写法：额外的给路由组件传递一些props
  // props:{a:1,b:2}
  // 函数写法：可以传递params参数、query参数，通过props传递给路由组件
  props: ($route) =>({keyword:$route.params.keyword,k:$route.query.k})
  },
  { path: '/login',component: ()=>import('@/pages/Login'), meta: { show: false } },
  { path: '/register', component: ()=>import('@/pages/Register'), meta: { show: false } },
  { path: '/detail/:skuid' , component: ()=>import('@/pages/Detail'), meta: { isShow: true } },
  { path: '/addcartsuccess', name: 'addcartsuccess', component: ()=>import('@/pages/AddCartSuccess'), meta: { isShow: true } },
  { path: '/shopcart', component: ()=>import('@/pages/ShopCart'), meta: { show: true }},
  { path: '/trade', component: ()=>import('@/pages/Trade'), meta: { show: true }, beforeEnter:(to,from, next) => {
    // 组件路由独享守卫 beforeEnter
    if(from.path == '/shopcart') {
      next()
    }else {
      next(false)
    }
  }},
  { path: '/pay', component: ()=>import('@/pages/Pay'), meta: { show: true }, beforeEnter:(to,from, next) => {
    if(from.path == '/trade') {
      next()
    }else {
      next(false)
    }
  }},
  { path: '/paysuccess', component: ()=>import('@/pages/PaySuccess'), meta: { show: true }},
  { path: '/center', component: ()=>import('@/pages/Center'), meta: { show: true }, children:[
    // 二级路由重定向
    { path: '/center', redirect: '/center/myorder' },
    // 二级路由
    {path: 'myorder', component: ()=>import('@/pages/Center/myOrder')},
    {path: 'grouporder', component: ()=>import('@/pages/Center/groupOrder')},
  ]}
]